/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package session;

import entity.RosterEntry;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Query;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Elise
 */
@Stateless
public class RosterEntryFacade extends AbstractFacade<RosterEntry> {
    @PersistenceContext(unitName = "PhoneShopPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public RosterEntryFacade() {
        super(RosterEntry.class);
    }

    public List queryFindAllForUser(String staffName){
        Query query = this.getEntityManager().createNamedQuery("findAllRosterEntriesForEmployee");
        query.setParameter("st", query);
        return query.getResultList();
    }

    public List queryFindAllForCurrentWeek(){
        //Obtain value for current week.
        Calendar cal = GregorianCalendar.getInstance();
        return queryFindAllForWeek(cal.get(cal.WEEK_OF_YEAR));
    }

    public List queryFindAllForWeek(int week){
        Query query = this.getEntityManager().createNamedQuery("findAllRosterEntriesForWeek");
        query.setParameter("w", week);
        return query.getResultList();
    }

    //Possibly needed
    public List queryFindAllForWeekBefore(int week){
        return queryFindAllForWeek(week-1);
    }
    public List queryFindAllForWeekAfter(int week){
        return queryFindAllForWeek(week+1);
    }

}
